import 'package:flutter/material.dart';
import '../common/common_ui.dart';

/* 对话框 */
class DialogPage extends StatefulWidget {
  @override
  _DialogPageState createState() => _DialogPageState();
}

class _DialogPageState extends State<DialogPage> {

  void navigateNamed(String routeName){
    Navigator.pushNamed(context, routeName);
  }

// class ButtonPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('按钮'),
        elevation: 0.0,
      ),
      body: Column(
        children: <Widget>[
          RaisedButton(
            onPressed: () async {
              //弹出对话框并等待其关闭
              bool delete = await showConfirmDialog(context, "您确定要删除该文件吗？", confirmBtnText: "删除");
              if (delete == null) {
                print("取消删除");
              } else {
                print("已确认删除");
                //... 删除文件
              }
            },
            child: Text('确认对话框'),
            textColor: Colors.white,
            color: Colors.lightBlue,
          ),
          RaisedButton(
            onPressed: () async {
              showLoadingDialog(context);
              Future.delayed(Duration(seconds: 2), (){
                  Navigator.of(context).pop(); // 关闭对话框
                  print('延时2s执行');
              });
            },
            child: Text('加载对话框'),
            textColor: Colors.white,
            color: Colors.lightBlue,
          ),
        ],
      ),  
    );
  }
  
}